package ThreadDemo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-09-17
 * Time: 13:27
 */
public class ThreadDemo6 {
    public static void main(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<3;i++){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"mythread");
        t.start();

        while(true){
            try {
                Thread.sleep(1000);
                System.out.println(t.isAlive());//每隔一秒判断线程是否存活
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
